<?php
use yii\helpers\Html;
use yii\helpers\Url;
/* @var $this yii\web\View */
$this->title = '注册';
?>
<section id="body_h">
		<div class='modular13'>
			<div class="modular12-con1from">
				<form action="<?= Url::to(['site/signup']); ?>" method="post" id="form-submit">
                <input type ="hidden" name="_csrf" value="<?php echo yii::$app->request->getCsrfToken();?>" />
					<p class="oneelement greenborder"><input name="name" class="changeelement" placeholder="请输入用户名" type="text"></p>
					<p class="oneelement greenborder"><input name="phone" class="changeelement" placeholder="请输入手机号" type="text"></p>
					<p class="oneelement greenborder"><input name="password" class="changeelement" placeholder="请输入您的密码" type="password"></p>
					<p class="oneelement greenborder"><input name="qrpassword" class="changeelement" placeholder="请再次输入您的密码" type="password"></p>
					<div class="twoelement haveborder">
						<input type="text" name="imgcode" class="changeelement greenborder border-r5 colorb" placeholder="请输入图片验证码">
						<p class="fixedelement2">
							<img width="100%" id="imgCode" src="<?php $token=file_get_contents(PANDA_SERVER.'/getTokenId'); $token=json_decode($token,true)['obj']; $session=yii::$app->session;$session->open();$session->set('tokenid',$token); echo PANDA_SERVER.'/getCAPTCHA'.'?tokenId='.$token;?>" alt="">
						</p>
					</div>
					<div class="twoelement haveborder">
						<input type="text" name="msgcode" class="changeelement greenborder border-r5 colorb" placeholder="请输入短信验证码">
						<p class="fixedelement2">
							<span id="getcode">获取验证码</span>
						</p>
					</div>
					<p class="modular12-con1ts1"><input name="xieyi" type="checkbox" value="" id="xieyiok" /><label for="xieyiok">同意<a href="<?= Url::to(['xieyi/index']);?>">《注册服务协议》</a></label></p>
					<p class="mould-2bot form-ok"><input class="form-okbtn b-f" type="submit" value="注册"></p>
					<p class="modular12-con1ts2 text-c">如有任何疑问，请拨打客服电话 <span class="bluecolor">4006-900-880</span> <br>工作时间：09：00-17：30</p>
				</form>
			</div>
		</div>
		<div class="footer-h"></div>
	</section>
	<section id="footer">
		<ul class="footer-nav clearfix">
		    <li class="current-bot">
		        <a href="<?= Url::to('main');?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer1-on.png" alt="">
		            首页
		        </a>
		    </li>
		    <li>
		        <a href="<?= Url::to('member');?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer2.png" alt="">
		            我的账户
		        </a>
		    </li>
		    <li>
		        <a href="<?= Url::to(['company/about']);?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer3.png" alt="">
		            关于我们
		        </a>
		    </li>
		</ul>
	</section>
	<p id="tip-error"><span>表单验证错误信息</span></p>
	<script>
	$(function($) {
	    var UA=window.navigator.userAgent;  //使用设备
	    var CLICK="click";
	    if(/ipad|iphone|android/.test(UA)){   //判断使用设备
	        CLICK="tap";
	    }
	    //获取验证码
	    $('#getcode').click(function(){
		    var name=$("input[name='name']").val();
			    phone=$("input[name='phone']").val();
			    password=$("input[name='password']").val();
			    qrpassword=$("input[name='qrpassword']").val();
	        	reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
	        	reg1 = /^[a-zA-Z\d]{6,16}$/;
	        	if(name == false){
					$('#tip-error span').html('姓名不能为空');
			        $('#tip-error').show();
			        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
	        		$("input[name='name']").focus();
	        	}else if(!reg.test(phone)){
					$('#tip-error span').html('请正确输入手机号');
			        $('#tip-error').show();
			        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
	        		$("input[name='phone']").focus();
	        	}else if(password == false){
					$('#tip-error span').html('密码不能为空');
			        $('#tip-error').show();
			        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
	        		$("input[name='password']").focus();
	        	}else if(!reg1.test(password)){
					$('#tip-error span').html('请输入6-16位密码');
			        $('#tip-error').show();
			        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
	        		$("input[name='password']").focus();
	        	}else if(qrpassword != password){
					$('#tip-error span').html('两次密码输入不一致');
			        $('#tip-error').show();
			        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
	        		$("input[name='password']").focus();
	        	}else{
					$.post(
							'<?= Url::to('sendcode');?>',
							{name:name,phone:phone,'_csrf':'<?= yii::$app->request->getCsrfToken();?>'},
							function(data)
							{
								var obj = eval('(' + data + ')');
								if(obj.msg == '操作成功！' && obj.status == 0)
								{
									$('#tip-error span').html('验证码已发送！');
							        $('#tip-error').show();
							        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
								}
								else
								{
									$('#tip-error span').html(obj.msg);
							        $('#tip-error').show();
							        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
								}
							});
				}
		   });
		   //开始注册
		$(".form-okbtn").click(function(event){
            event.preventDefault();
            var name=$("input[name='name']").val();
		    phone=$("input[name='phone']").val();
		    password=$("input[name='password']").val();
		    qrpassword=$("input[name='qrpassword']").val();
        	reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
        	reg1 = /^[a-zA-Z\d]{6,16}$/;
        	if(name == false){
				$('#tip-error span').html('姓名不能为空');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='name']").focus();
        	}else if(!reg.test(phone)){
				$('#tip-error span').html('请正确输入手机号');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='phone']").focus();
        	}else if(password == false){
				$('#tip-error span').html('密码不能为空');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='password']").focus();
        	}else if(!reg1.test(password)){
				$('#tip-error span').html('请输入6-16位密码');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='password']").focus();
        	}else if(qrpassword != password){
				$('#tip-error span').html('两次密码输入不一致');
		        $('#tip-error').show();
		        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
        		$("input[name='password']").focus();
        	}else{
				$('#form-submit').submit();
			}
		});
		$(".bodyA").hide();
	});
	//图片验证码刷新
	$("#imgCode").click(function(){
			document.getElementById("imgCode").src="<?= PANDA_SERVER.'/getCAPTCHA'.'?tokenId='.$token;?>"+'&time='+Math.random();
	});
</script>
